/*
 * @Description: 
 * @Author: yucheng
 * @Date: 2024-07-19
 * @LastEditors: 余承
 * @LastEditTime: 2024-07-21
 */
import axios, {AxiosError, type AxiosResponse} from 'axios'

const instance = axios.create({
  baseURL: 'http://111.56.142.55:10019',
  timeout: 10000,
});

const handleResponse = (response: AxiosResponse) => {
  return response.data;
};

const handleError = (error: AxiosError) => {
  return Promise.reject(error);
};

instance.interceptors.response.use(handleResponse, handleError);

const get = async (url: string, params?: any) => {
  try {
    const response = await instance.get(url, { params });
    return response;
  } catch (error) {
    throw error;
  }
};

const post = async (url: string, data?: any) => {
  try {
    const response = await instance.post(url, data);
    return response;
  } catch (error) {
    throw error;
  }
};

const http = {
    get,
    post,
}
export default http